<?php 
/**
 * index.php
 * 
 * The webpage that users will first encounter when visiting the HyperLinks website.
 * From this webpage users can access the Login, Logout, Register, and Forgot Password webpages.
 */
require_once 'connect.php';
require_once 'interface.php';
session_start();
webpageDoctype();
print_html_title("Welcome");
webpageMetaAndBodyStart();

// If the "hyperlinks" database does not exist, create the necessary database and table.
if (!$db) {
	mysql_query("CREATE DATABASE hyperlinks",$con);
	mysql_select_db("hyperlinks",$con);
	mysql_query("CREATE TABLE users "
			. "(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
			. "username VARCHAR(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, "
			. "password VARCHAR(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, "
			. "email VARCHAR(55) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, "
			. "preferences VARCHAR(16) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, "
			. "code VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, "
			. "active INT(1) NOT NULL, "
			. "date INT(11) NOT NULL) ENGINE = MyISAM",$con);
}
mysql_close($con);
?>
<p>
<div align="center">
<h2>
<?php
if ($_SESSION['userid'] == NULL || $_SESSION['username'] == NULL) {
	echo <<<EOL
<a href="./login.php">Login</a>
<br /><br />
EOL;
}
if (strlen($_SESSION['username']) > 0 && strlen($_SESSION['userid']) > 0) {
	echo <<<EOL
<a href="./logout.php">Logout</a>
<br /><br />
EOL;
}
?>
<a href="./register.php">Register</a>
<br /><br />
<a href="./forgotpass.php">Forgot Password</a>
<br />
</h2>
</div>
</p>
<?php
webpageFooter();
?>
